package com.mikeli.javacourse.lesson3.homework.gateway.filter.impl;

import cn.hutool.core.util.StrUtil;
import com.mikeli.javacourse.lesson3.homework.gateway.filter.HttpRequestFilter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;

public class HttpRequestURIFilter implements HttpRequestFilter {
    /**
     * 统一请求到 /test
     * @param fullRequest
     * @param ctx
     */
    @Override
    public void filter(FullHttpRequest fullRequest, ChannelHandlerContext ctx) {
        String uri = fullRequest.uri();
        if (!StrUtil.contains(uri, "test")) {
            uri += uri.endsWith("/") ? "test" : "/test";
        }
        fullRequest.setUri(uri);
    }
}
